<template>
    <div class="container" id="home">
        <div class="top-banner">
            <img src="http://47.75.99.213/app/cdn/banner.jpg" class="image">
            <div class="blank-9"></div>
        </div>
        <loadmore :layout="'fixed'"></loadmore>
    </div>
</template>

<script>
import loadmore from "@/components/Loadmore/index"
import { setCookie,getCookie } from '@/utils/auth'
export default {
    data(){
        return{
            scrollTop : 0
        }
    },
    components:{
        loadmore
    },
    mounted(){
        document.getElementById("loadmore").addEventListener('scroll', this.handleScroll);
    },
    activated(){
        if( getCookie('1') ){
            this.scrollTop = getCookie('1')
        }else{
            this.scrollTop = 0;
        }

        if(this.scrollTop > 0){
            document.getElementById("loadmore").scrollTop = this.scrollTop;
            // document.getElementById("loadmore").scrollTo(0, this.scrollTop);  // 移动端webview不兼容scrollTo方法
            document.getElementById("loadmore").addEventListener('scroll', this.handleScroll);
        }
    },
    methods: {
        handleScroll () {
            this.scrollTop = document.getElementById("loadmore").scrollTop;
        }
    },
    beforeRouteLeave(to,form,next){
        var date = new Date();
        date.setTime(date.getTime()+6000*1000);//只能这么写，6000表示6000秒
        setCookie('1',this.scrollTop,date)
        next()
    }
}
</script>

<style lang="stylus" scoped>
.container{
    width:100%;
}
</style>

